<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/config.inc.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');

$section_id = mysql_real_escape_string(strip_tags($_POST['sec_id']));
$csm_id = mysql_real_escape_string(strip_tags($_POST['csm_id']));
$course_id = mysql_real_escape_string(strip_tags($_POST['cid']));
$subject_id = mysql_real_escape_string(strip_tags($_POST['sid']));
$cl_course_id = mysql_real_escape_string(strip_tags($_POST['new_cl']));

$get_subject_data = mysql_query("SELECT * FROM course_subjects WHERE id = $subject_id");
$subject_name = mysql_result($get_subject_data,0,'subject_title');
$abbreviation = mysql_result($get_subject_data,0,'abbreviation');

$get_course_data = mysql_query("SELECT * FROM courses WHERE id = $course_id");
$course_number = mysql_result($get_course_data,0,'course_number');
$course_name = mysql_result($get_course_data,0,'title');

$get_section_data = mysql_query("SELECT * FROM course_sections WHERE id = $section_id");
$section_number = mysql_result($get_section_data,0,'section_number');

//counting variable
$i = 0;

$formatted_section_number = sprintf("%03d", $section_number);

echo "<h1>Add Crosslisting for $abbreviation $course_number - $formatted_section_number</h1>";

$query = "SELECT * FROM course_section_mapping WHERE course_section_id = '$section_id'";
$result = mysql_query($query);
$rank = mysql_numrows($result);
$rank++; 

$query2 = "INSERT INTO course_section_mapping (id, course_section_id, course_id, scheduling_rank)
VALUES
('','$section_id','$cl_course_id','$rank')";

$result2 = mysql_query($query2);

if ($result2)
{
	echo "Crosslisting has been successfully added for section <b>$formatted_section_number</b>!";
	echo "<br />";
}
else
{
	echo "Crosslisting was NOT able to be added for section <b>$formatted_section_number</b> at this time!";
	echo "<br />";
}

//close
mysql_close();

echo "<p>";
	echo "<a href='index.php?sid=$subject_id&csm_id=$csm_id&cid=$course_id&sec_id=$section_id'>&lt;&lt; Back to Section Crosslisting Portal</a><br />";
echo "</p>";
?>

<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/bottom.inc.php');
?>